#include <iostream>
#include "dragon.hpp"


using namespace std;


Dragon::Dragon(int age):
    age(age)
{
}


int Dragon::vertex_num(void)
{
    return (1 << age)*2;
}


void Dragon::render(FVertexArray<FVector2d> &va, int age, FVector2d &l, FVector2d &r)
{
    if (age == 0) {
	va.push_back(l);
	va.push_back(r);
	return;
    }
    FVector2d l1, r1;
    l1.x = 0.5*l.x + 0.5*l.y;
    l1.y = -0.5*l.x + 0.5*l.y;

    r1.x = 0.5*r.x + 0.5*r.y;
    r1.y = -0.5*r.x + 0.5*r.y;

    render(va, age-1, l1, r1);

    l1.x = -0.5*l.x + 0.5*l.y - 1;
    l1.y = -0.5*l.x - 0.5*l.y;

    r1.x = -0.5*r.x + 0.5*r.y - 1;
    r1.y = -0.5*r.x - 0.5*r.y;

    render(va, age-1, l1, r1);
}
